//
//  pushController.m
//  RealEstateQa
//
//  Created by 张立彬 on 13-8-2.
//  Copyright (c) 2013年 com.rong360. All rights reserved.
//

#import "pushController.h"

@interface pushController ()

@end

@implementation pushController

@synthesize url;
@synthesize PushWebView;
@synthesize notification;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    PushWebView.delegate = self;
    
    [self pushCome:notification];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) webViewDidStartLoad:(UIWebView *)web
{
    if(web == PushWebView){
        //NSLog(@"当前webview:%@",web);
        webLoading.hidden = NO;
        [webLoading startAnimating];
        toolBarReload.hidden = YES;
        toolBarGoBack.enabled = ([self.PushWebView canGoBack]);
        toolBarGoPre.enabled = ([self.PushWebView canGoForward]);
    }
}

- (void) webViewDidFinishLoad:(UIWebView *)web
{
    if(web == PushWebView){
        //NSLog(@"当前webview:%@",web);
        webLoading.hidden = YES;
        [webLoading startAnimating];
        toolBarReload.hidden = NO;
        toolBarGoBack.enabled = ([self.PushWebView canGoBack]);
        toolBarGoPre.enabled = ([self.PushWebView canGoForward]);
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
    }
    
}


//消息触发
-(void)pushCome:(NSNotification*) notification
//-(void)pushCome
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;    
    
    PushWebView.frame = CGRectMake(0, 0, 320, size.height-60);
    PushToolBar.frame = CGRectMake(0, size.height-60, 320, 40);

    webLoading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    webLoading.frame = CGRectMake(150, 10, 20, 20);
    [PushToolBar addSubview:webLoading];
    [webLoading startAnimating];
    
    NSDictionary *imformation = [[NSDictionary alloc] init];
    imformation = (NSDictionary *)notification;
    //NSLog(@"imformation:%@",imformation);
    NSDictionary* text =[[NSDictionary alloc] init];
    text = notification.userInfo;
    
    //NSString *pushType = [text objectForKey:@"type"];
    NSString *pushUrl = [text objectForKey:@"url"];
    //NSLog(pushMsg);
    
    //NSString *pushUrl = @"http://www.baidu.com";
    
    [PushWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pushUrl]]];
    
    toolBarGoBack.enabled = NO;
    toolBarGoPre.enabled = NO;
    toolBarReload.hidden = YES;
    webLoading.hidden = NO;
    
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    
}


//返回首页
-(IBAction)TapReturn:(id)sender{
    //自定义动画
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.3];
    [animation setType: kCATransitionMoveIn];
    [animation setSubtype: kCATransitionFromBottom];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    [self.navigationController.view.layer addAnimation:animation forKey:nil];
    [self.navigationController popViewControllerAnimated:NO];
}


@end
